<?php $this->pageTitle = 'Receipts'; ?>
<?php Yii::app()->clientScript->registerScriptFile('/js/jquery.cookie/jquery.cookie.js'); ?>
<div class="flat_area">
	<div class="main-title no-border clearfix">
		<h1 class="float-left">Receipts</h1>
		<div class="controls">
			<a id="addReceipt" class="link-button with-icon <?php echo Yii::app()->user->hasOneAgencySelected() ? "" : "disabled"; ?>" href="<?php echo Yii::app()->user->hasOneAgencySelected() ? $this->createUrl('receipt/create') : "javascript:void(0);"; ?>">
				<img src="/images/icons/fugue/document--plus.png" />
				Receive Payment
			</a>
		</div>
	</div>
	<div class="grid_16 relative">
		<div class="search-form">
			<?php
			$this->renderPartial('_search', array(
				'receipt' => $receipt,
			));
			?>
		</div><!-- search-form -->
		<div id="ps-receipt-index">
			<?php
			$this->widget('PsGridView', array(
				'id' => 'receipt-index-grid',
				'dataProvider' => $dataProvider,
				'template' => '{items}{pager}{pagesize}',
				'emptyText' => $emptyText,
				'htmlOptions' => array(
					'class' => 'grid-view grey'
				),
				'pagerCssClass' => 'pager float-right',
				'pagesizeCssClass' => 'pager-pagesize float-right',
				'rowCssClassExpression' => '($data->deleted == 1 ? "deleted" : "")',
				'columns' => array(
					array(
						'header' => 'Receipt Date',
						'type' => 'raw',
						'name' => 'payment_date',
						'value' => 'Yii::app()->dateFormatter->formatDateTime(strtotime($data->payment_date), "short", null)',
						'htmlOptions' => array(
							'width' => 90,
							'class' => 'valign-top'
						)
					),
					array(
						'header' => 'Receipt #',
						'name' => 'payment_number',
						'type' => 'raw',
						'value' => 'CHtml::link("#" . $data->payment_number, array("receipt/view", "id" => $data->id), array("class" => "blue link"))',
						'headerHtmlOptions' => array('width' => 100),
						'htmlOptions' => array(
							'class' => 'valign-top'
						)
					),
					array(
						'header' => 'Received From',
						'name' => 'payer_name',
						'type' => 'raw',
//						'value' => 'CHtml::link($data->payer_name, array("party/view", "id" => $data->payer_party_id), array("class" => "blue link received-from"))'
						'htmlOptions' => array('class' => 'valign-top')
					),
					array(
						'header' => 'Agent Name',
						'type' => 'raw',
						'value' => '$data->getReceiptRelatedMainAgent()',
						'htmlOptions' => array('class' => 'valign-top')
					),
					array(
						'header' => 'Payment Method',
						'name' => 'payment_method_type_code',
						'value' => '$data->getPaymentMethod()',
						'headerHtmlOptions' => array('width' => 120),
						'htmlOptions' => array(
							'class' => 'valign-top'
						)
					),
					array(
						'header' => 'Payment Cleared?',
						'name' => 'payment_cleared_date',
						'value' => '$data->isPaymentCleared() ? "Yes" : ""',
						'headerHtmlOptions' => array('width' => 120),
						'htmlOptions' => array(
							'class' => 'valign-top'
						)
					),
					array(
						'header' => 'Payment Ref No',
						'name' => 'payment_ref_no',
						'value' => '$data->payment_ref_no ? $data->payment_ref_no : "-"',
						'headerHtmlOptions' => array('width' => 100),
						'htmlOptions' => array(
							'class' => 'valign-top'
						)
					),
					array(
						'header' => 'Amount Received',
						'name' => 'amount',
						'type' => 'raw',
						'value' => 'Yii::app()->numberFormatter->formatCurrency($data->amount, $data->currency_code)',
						'headerHtmlOptions' => array('class' => 'align-right'),
						'htmlOptions' => array('class' => 'valign-top align-right'),
					),
					array(
						'header' => 'Applied to Invoice No',
						'class' => 'common.widgets.grid.PsPartialViewColumn',
						'view' => '_applied_to_column',
						'htmlOptions' => array('class' => 'valign-top')
					),
					'agency' => array(
						'header' => 'Agency',
						'name' => 'agencyName',
						'type' => 'raw',
						'value' => '$data->ownerParty->getAgency()->name',
						'filter' => false,
						'headerHtmlOptions' => array('width' => 120),
						'htmlOptions' => array('class' => 'agency-column no-wrap'),
						'visible' => Yii::app()->user->hasMultipleAgenciesSelected()
					),
				),
			));
			?>
		</div>
		<div>
			<?php if (!$showDeleted): ?>
				<a class="float-left blue link" href="<?php echo $this->createUrl('receipt/index', array('showDeleted' => true, 'view' => $view)); ?>">Show Deleted</a>
			<?php else: ?>
				<a class="float-left blue link" href="<?php echo $this->createUrl('receipt/index', array('view' => $view)); ?>">Hide Deleted</a>
			<?php endif; ?>
		</div>
	</div>
</div>
<script type="text/javascript">
	var welcomePopupEnabled = <?php echo ($welcomePopupEnabled ? "true" : "false"); ?>;
	var showWhatsNew = <?php echo ($showWhatsNew ? "true" : "false"); ?>;
</script>